import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class NeuerFilm extends Frame implements ActionListener{
	
	JButton btn_Anlegen = new JButton ("Anlegen");
	JLabel lbl_Titel = new JLabel("Tite: l");
	JTextField txt_Titel = new JTextField();
	JLabel lbl_Dauer = new JLabel("Dauer in Minuten: ");
	JTextField txt_Dauer = new JTextField();
	JLabel lbl_Genere = new JLabel("Genere: ");
	JTextField txt_Genere = new JTextField();
	JLabel lbl_Preis = new JLabel("Preis: ");
	JTextField txt_Preis = new JTextField();
	JLabel lbl_headline = new JLabel("Neuer Film anlegen");
	
	private int dauer, filmnr;
	private double preis1,preis2;
	private String titel, genere,beschreibung;
	
	Database database=null;

	
	public NeuerFilm (Database database){
		super("Film anlegen");
		addWindowListener(new WindowsClosingAdapter(true));
		this.database=database;
		setLayout(new GridLayout(5, 2));
		add(lbl_headline);
		add(btn_Anlegen);
		add(lbl_Titel);
		add(txt_Titel);
		add(lbl_Genere);
		add(txt_Genere);
		add(lbl_Preis);
		add(txt_Preis);
		add(lbl_Dauer);
		add(txt_Dauer);
		
		btn_Anlegen.addActionListener(this);
		
		pack();
		setVisible(true);
	}



	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		
		
		genere = txt_Genere.getText();
		titel = txt_Titel.getText();
		dauer = Integer.parseInt(txt_Dauer.getText());
		preis1 = Double.parseDouble(txt_Preis.getText());
		
		Film newMove = new Film(titel, dauer, genere, preis1);
		
		try {
			database.setMove(newMove);
			setVisible(false);
			database.selectAllFrom(2);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
}
